package com.thor.palmmall.rest.order.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.order.AOrder;
import com.thor.palmmall.rest.order.OrderDateUtil;
import com.thor.palmmall.spi.common.SOperateInfoConverter;
import com.thor.palmmall.spi.order.SOrder;
import com.thor.palmmall.spi.order.SOrderActivitie;
import com.thor.palmmall.spi.order.SProductLine;

public class SOrderConverter implements Converter<AOrder,SOrder>  {
	public static SOrderConverter getInstance() {
		if (instance == null)
			instance = new SOrderConverter();
		return instance;
	}

	private static SOrderConverter instance;
	@Override
	public SOrder convert(AOrder source) {
		SOrder target = new SOrder();
		target.setUuid(source.getUuid());
		target.setVersion(source.getVersion());
		target.setVersionTime(source.getVersionTime());
		target.setCreateInfo(SOperateInfoConverter.getInstance().convert(source.getCreateInfo()));
		target.setLastModifyInfo(SOperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
		target.setBillNumber(source.getBillNumber());
		target.setBizState(source.getBizState());
		target.setInstall(source.isInstall());
		target.setStore(UCN.newInstance(source.getStore()));
		target.setContract(UCN.newInstance(source.getContract()));
		target.setTenant(UCN.newInstance(source.getTenant()));
		if(source.getActivities() != null){
			target.setActivities(SOrderActivitieConverter.getInstance().convert(source.getActivities()));
		}else{
			target.setActivities(new ArrayList<SOrderActivitie>());
		}
		if(source.getPreActivities() != null){
			target.setPreActivities(SOrderActivitieConverter.getInstance().convert(source.getPreActivities()));
		}else{
			target.setPreActivities(new ArrayList<SOrderActivitie>());
		}
		target.setFileIds(source.getFileIds()==null?new ArrayList<String>():source.getFileIds());
		target.setBoothNumber(source.getBoothNumber());
		target.setBoothTelephone(source.getBoothTelephone());
		target.setAppointmentDeliveryDate(OrderDateUtil.parseUTC(source.getAppointmentDeliveryDate()));
		target.setDeliveryMode(source.getDeliveryMode());
		target.setCustomerName(source.getCustomerName());
		target.setCustomerTelephone(source.getCustomerTelephone());
		target.setOrderDate(OrderDateUtil.parseUTC(source.getOrderDate()));
		target.setReceiptAddress(source.getReceiptAddress());
		target.setPaymentCategory(source.getPaymentCategory());
		target.setRemark(source.getRemark());
		target.setGift(source.getGift());
		target.setRemark(source.getRemark());
		target.setVoucher(source.getVoucher());
		target.setLines(source.getLines()!=null?SProductLineConverter.getInstance().convert(source.getLines()):new ArrayList<SProductLine>());
		target.setStdTotal(source.getStdTotal());
		target.setReturnedTotal(source.getReturnedTotal());
		target.setVoucherTotal(source.getVoucherTotal());
		target.setPayTotal(source.getPayTotal());
		target.setSettledTotal(source.getSettledTotal());
		target.setAccountTotal(source.getAccountTotal());
//		target.setFeeTotal(source.getFeeTotal());
		target.setDiscountRate(source.getDiscountRate());
		target.setPayDate(source.getPayDate());
		target.setMemberCardNo(source.getMemberCardNo());
		target.setDesignerName(source.getDesignerName());
		target.setDesignerPhone(source.getDesignerPhone());
		target.setOrderMark(source.getOrderMark());
		target.setPreDeposit(source.getPreDeposit());
		return target;
	}
}
